﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Gencode.PrsCommon.App;

namespace Personalplaner.Options
{
    [ToolboxItem(false)]
	public partial class PersonDisplay : Gencode.Gengui.GUControl/* UserControl*/, IOptionsInterface
	{
		bool changed = false;

		public PersonDisplay()
		{
			InitializeComponent();
			SetOptions();
		}

		private void SetOptions()
		{
			bool check = false;
			if ((int)Option.NumberValue("PersonDisplaOptions", 1) == 1) { check = true; } else { check = false; }
			checkShowAbteilungsName.Checked = check;

			if ((int)Option.NumberValue("PersonDisplaOptions", 2) == 1) { check = true; } else { check = false; }
			checkShowMonth.Checked = check;

			if ((int)Option.NumberValue("PersonDisplaOptions", 3) == 1) { check = true; } else { check = false; }
			checkShowSaldo.Checked = check;

			if ((int)Option.NumberValue("PersonDisplaOptions", 4) == 1) { check = true; } else { check = false; }
			checkPlanName.Checked = check;

			changed = false;
		}

		#region IOptionsInterface Members

		public void save()
		{
			if (changed)
			{
				double check = 0;

				if (checkShowAbteilungsName.Checked) { check = 1; } else { check = 0; }
				SaveOptions.SaveData("PersonDisplaOptions", 1, check, "");

				if (checkShowMonth.Checked) { check = 1; } else { check = 0; }
				SaveOptions.SaveData("PersonDisplaOptions", 2, check, "");

				if (checkShowSaldo.Checked) { check = 1; } else { check = 0; }
				SaveOptions.SaveData("PersonDisplaOptions", 3, check, "");

				if (checkPlanName.Checked) { check = 1; } else { check = 0; }
				SaveOptions.SaveData("PersonDisplaOptions", 4, check, "");

				//Reload options in GPerson
				GPerson.SetData();

				changed = false;
			}
		}

		public bool checkIfChanged()
		{
			return changed;
		}

		#endregion

		private void checkShowAbteilungsName_CheckedChanged(object sender, EventArgs e)
		{
			changed = true;
		}

		private void checkShowMonth_CheckedChanged(object sender, EventArgs e)
		{
			changed = true;
		}

		private void checkShowSaldo_CheckedChanged(object sender, EventArgs e)
		{
			changed = true;
		}

		private void checkPlanName_CheckedChanged(object sender, EventArgs e)
		{
			changed = true;
		}
	}
}
